package main.model.island;

import java.awt.Color;
import java.util.Random;

public class ColorGenerator {
	
	public static Color getSkinColor(){
        int maxCol = 100;
        Random r = new Random();
        int valueCol = r.nextInt(maxCol);
        //valueCol = 8;
        return getSkinColor(valueCol,maxCol);
    }
	/**
	 * Transforms RGB colours between a set of shades into a linear scale.
	 * 
	 * 
	 * @param valueCol
	 * @param maxCol
	 * @return
	 */
    private static Color getSkinColor(int valueCol,int maxCol){
    	//color codes for setting critters
    	//RGB,
        int[][] codec = {{0,1,1,1,-1},{0,0,1,0,1},{1,0,1,2,-1},{1,0,0,1,1}};
        
        
        double per = (double)valueCol/((double)maxCol/codec.length);
        int fper = (int)Math.floor(per);
        if(valueCol>=maxCol){
            fper = 3;
        }
        int[] rgb = {255*codec[fper][0],255*codec[fper][1],255*codec[fper][2]};
        int modifier = (int)(255*(per-fper)*codec[fper][4]);
        rgb[codec[fper][3]] = rgb[codec[fper][3]]+modifier;
        int darken = 15;
        if(rgb[0]>darken){rgb[0]=rgb[0]-darken;}
        if(rgb[1]>darken){rgb[1]=rgb[1]-darken;}
        if(rgb[2]>darken){rgb[2]=rgb[2]-darken;}
        return new Color(rgb[0],rgb[1],rgb[2]);
    }
}
